<template>
    <div>
        <!-- tab-top-webview-main -->
		<!-- 滑动导航 -->
       <div id="slider" class="mui-slider">
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<!-- tap的作用跟 click类似 但tap只能用在mui中 -->
					<a v-for="item in catesList" :key="item.id" @tap="getCategoryList(item.id)" :class="['mui-control-item',item.id==0?'mui-active':'']" data-wid="tab-top-subpage-1.html">
						{{ item.title}}
					</a>
					
				</div>
			</div>
		</div>

		<!-- 图片内容区 -->
		<ul class="photo-list">
			<!-- tag=li的作用,让router-link渲染的标签为li  即在浏览器下查看代码时看到是li标签 -->
			<router-link v-for="item in list" :key="item.id" :to="'/home/photolist/photoInfo/'+item.id" tag="li">
				<img v-lazy="item.img_url">
				<div class="info">
					<h1 class="info-title">{{item.title}}</h1>
					<div class="info-body">{{item.zhaiyao}}</div>
				</div>
			</router-link>
		</ul>
    </div>
</template>
<script>
//使用导入以下mui需要移除严格模式
import mui from "../../lib/mui/js/mui.min.js";
import { Toast } from 'mint-ui'

export default {
	data(){
		return{
			catesList:null,
			list:{}
		}
	},
	mounted(){
		mui('.mui-scroll-wrapper').scroll({
			deceleration:0.0005//flick 减速系数,系数越大,滚动速度越慢 ,滚动距离越小,默认值0.0006
		});
	},
	created() {
		this.getAllCategory()
		this.getCategoryList(0)//默认加载所有图片内容
	},
	methods:{
		//从后台获取导航栏列表
		getAllCategory(){
			this.$http.get("photocates.json").then(result=>{
				if (result.body) {
					this.catesList = result.body
				} else {
					Toast("获取数据失败!!!")
				}
				
			})
		},
		//从后台加载图片内容 图片内容,并传入id --------目的实现tab切换效果
		getCategoryList(id){
			this.$http.get("photos.json").then(result=>{
				if (result.body) {
					console.log(result.body)
					if (id ==0 ) {//当 id=0时 表示单击"全部"所以显示所有的内容
						this.list = result.body
					} else {
						this.list = result.body.filter(item =>{
							if (item.cateid == id) {
								return item
							}
						})						
					}
					console.log(this.list)
				} else {
					Toast("获取数据失败！！！")
				}
			})
		}
	},
}
</script>

<style lang="scss" scoped>
/* 解决警告加以下样式[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL> */
	/* 是chrom 为了提高滑动流畅度 */
	* { touch-action: pan-y; }
	.photo-list{
		list-style: none;
		margin: 0;
		padding: 10px;
		padding-bottom: 0;

		li{
			background-color: #ccc;
			text-align: center;
			margin-bottom: 10px;
			box-shadow: 0 0 9px #999;
			position: relative;
			
			img{
				width: 100%;
				height: 300px;
			}

			image[lazy=loading] {
				width: 40px;
				height: 300px;
				margin: auto;
			}

			 .info {
				 width: 100%;
				color: white;
				text-align: left;
				position: absolute;
				bottom: 0;
				background-color: rgba(0, 0, 0, 0.4);
				max-height: 84px;
				.info-title {
					font-size: 14px;
				}
				.info-body {
					font-size: 13px;
				}
			 }
		}

	}
	
</style>